package com.hubing.cloud.app.web.controller;

import com.alibaba.fastjson2.JSONObject;
import com.hubing.cloud.app.web.model.ResponseBean;
import com.hubing.cloud.app.web.model.dto.DocDto;
import com.hubing.cloud.app.web.model.dto.ItemKeyDto;
import com.hubing.cloud.app.web.service.DocService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("doc")
public class DocController {

    @Autowired
    private DocService docService;

    /**
     * 查看 - 文章
     *
     * @return
     */
    @PostMapping("/showDoc")
    public ResponseBean showDoc(@RequestBody ItemKeyDto dto) {
        String menuId = dto.getItemKeys();
        JSONObject result = docService.showDoc(menuId);
        return ResponseBean.success(result);
    }

    /**
     * 保存 - 文章
     *
     * @return
     */
    @PostMapping("/saveDoc")
    public ResponseBean saveDoc(@RequestBody DocDto dto) {
        docService.saveDoc(dto);
        return ResponseBean.success();
    }

    /**
     * 删除 - 文章
     *
     * @return
     */
    @PostMapping("/deleteDoc")
    public ResponseBean deleteDoc(@RequestBody ItemKeyDto dto) {
        String docId = dto.getItemKeys();
        docService.deleteDoc(docId);
        return ResponseBean.success();
    }
}
